const { ccclass, menu, property } = cc._decorator;

@ccclass
@menu('TextureDisperse/TextureDisperse')
export default class TextureDisperse extends cc.Component {

    /** 图片 */
    @property({ type: cc.Sprite, tooltip: '图片' })
    tiledSprite: cc.Sprite = null;

    onBtnSlice() {

    }

    onBtnDisperse() {
        let growSpeedOfTargetR = 10;
        let that = this;
        this.schedule((dt) => {
            let width = this.tiledSprite.node.getBoundingBox().width;
            let height = this.tiledSprite.node.getBoundingBox().height;
            let initalTargetR = new cc.Vec2(width, height);
            let center = this.tiledSprite.node.position;

            // var initalTargetR = cc.pLength(
            //     cc.p(
            //         this.tiledSprite.getBoundingBox().width, 
            //         this.tiledSprite.getBoundingBox().height
            //     )
            // );
            // var center = this.tiledSprite.getPosition();
            // for(var i = 0; i < that.gridSize.width; i ++) {
            //     for( j = 0; j < that.gridSize.height; j ++) {
            //         var tile = TiledGrid3DUtil.getTile(that.tiledSpriteTile, cc.p(i, j));
            //         //current target R
            //         var targetR = initalTargetR + dt * growSpeedOfTargetR;
            //         //update postion
            //         var fragPos = TiledGrid3DUtil.getTilePosition(that.tiledSpriteTile, cc.p(i, j));
            //         var disToCenter = cc.pLength(cc.p(fragPos.x - center.x, fragPos.y - center.y));
            //         var dir = cc.p(0, 0);
            //         if (disToCenter == 0) {
            //             dir = cc.p(0, 0);
            //         }
            //         else {
            //             dir = cc.p(fragPos.x - center.x, fragPos.y - center.y);
            //             dir.x /= -disToCenter;
            //             dir.y /= -disToCenter;
            //         }
            //         var disToEdge = targetR - disToCenter;
            //         var disToEdgeWithRandom = disToEdge - initalTargetR / 2;
            //         var movLen = disToEdgeWithRandom * 0.05;
            //         var movVec = cc.pMult(dir, movLen);
            //         TiledGrid3DUtil.updateTilePosition(that.tiledSpriteTile, cc.p(i, j), cc.p(fragPos.x + movVec.x, fragPos.y + movVec.y));
            //     }
            // }
            // TiledGrid3DUtil.showTileWorld(that.tiledSpriteTile, that);
        }, 0, 50, 0);
    }

    onBtnMove() {

    }
}
